#pragma once

#include <sys/socket.h>
#include <netinet/in.h>
#include <ctime>

class UtilTimer; // resolve cross references

struct ClientData
{
    sockaddr_in address_;
    int sockfd_;
    UtilTimer* timer_;
};

class UtilTimer
{
public:
    UtilTimer(): prev_(nullptr), next_(nullptr) {}
private:
    time_t expire_;

    // @TODO: use functor instread of it
    void (*Callback)(ClientData *); 
    ClientData userData_;
    UtilTimer *prev_;
    UtilTimer *next_;
};

class SortTimerList
{
public:
    SortTimerList();
    ~SortTimerList();

    void addTimer(UtilTimer* timer);
    void adjustTimer(UtilTimer* timer);
    void deleteTimer(UtilTimer* timer);
    void tick();
private:
    void addTimer(UtilTimer* timer, UtilTimer* head);
    
    UtilTimer *head_;
    UtilTimer *tail_;
};

class Util
{

};

void Callback(ClientData* userData);